package com.mdd.front.service.system.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdd.common.entity.system.SystemDevPay;
import com.mdd.common.mapper.system.SystemDevPayMapper;
import com.mdd.common.utils.StringUtil;
import com.mdd.front.service.system.ISystemDevPayService;
import com.mdd.front.vo.system.SystemDevWxPayConfig;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.annotation.Resource;

/**
 * 支付配置实现类
 * @author panweiliang
 */
@Service
public class SystemDevPayServiceImpl implements ISystemDevPayService {
    @Resource
    SystemDevPayMapper systemDevPayMapper;

    /**
     * 支付配置
     *
     * @author panweiliang
     * @param id 主键参数
     * @return SystemDevPay
     */
    @Override
    public SystemDevWxPayConfig getWxPayConfig(Integer id) {
        SystemDevPay model = systemDevPayMapper.selectOne(
                new QueryWrapper<SystemDevPay>()
                        .eq("id", id)
                        .last("limit 1"));
        Assert.notNull(model, "数据不存在");
        String configJson = model.getConfig();
        if (StringUtil.isNotEmpty(configJson)) {
            JSONObject configJsonObj = JSONObject.parseObject(configJson);
            return configJsonObj.toJavaObject(SystemDevWxPayConfig.class);
        }
        return null;
    }

}
